import { ArkcubeScriptParser, FunctionApplyContext, FunctionDeclContext, FunctionDeclStatementContext, ProgramContext } from '../gen/ArkcubeScriptParser';
import { ArkcubeScriptVisitor } from '../gen/ArkcubeScriptVisitor';
import { ArkcubeScriptLexer } from '../gen/ArkcubeScriptLexer';
import * as AntlrUtils from './AntlrUtils';
import { DocumentManager } from './DocumentManager';

import { ParseTree } from 'antlr4ts/tree/ParseTree';
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor'
import { RuleNode } from 'antlr4ts/tree/RuleNode';
import { TerminalNode } from 'antlr4ts/tree/TerminalNode';
import { ErrorNode } from 'antlr4ts/tree/ErrorNode';
import { TokenStreamRewriter } from 'antlr4ts/TokenStreamRewriter';
import { BufferedTokenStream } from 'antlr4ts/BufferedTokenStream';
import { Token } from 'antlr4ts/Token';
import { CharStreams, CommonTokenStream } from 'antlr4ts';
import { Diagnostic } from 'vscode-languageserver';


export class ArkcubeScriptValidator extends AbstractParseTreeVisitor<null> implements ArkcubeScriptVisitor<null> {

	private diagnostics: Diagnostic[] = [];

	private documentManager: DocumentManager;

	constructor(documentManager: DocumentManager) {
		super();
		this.documentManager = documentManager;
	}

	static validate(documentManager: DocumentManager, uri: string, maxNumberOfProblems: number): Diagnostic[] {
		let tree = documentManager.getOrCreateAST(uri);
		if (!tree) {
			return [];
		}

		let validator = new ArkcubeScriptValidator(documentManager);
		validator.visitProgram(tree);
		return validator.diagnostics;



		let problems = 0;

		// const pattern = /\b[A-Z]{2,}\b/g;
		// let m: RegExpExecArray | null;

		// while ((m = pattern.exec(text)) && problems < settings.maxNumberOfProblems) {
		// 	problems++;
		// 	const diagnostic: Diagnostic = {
		// 		severity: DiagnosticSeverity.Warning,
		// 		range: {
		// 			start: textDocument.positionAt(m.index),
		// 			end: textDocument.positionAt(m.index + m[0].length)
		// 		},
		// 		message: `${m[0]} is all uppercase.`,
		// 		source: 'ex'
		// 	};
		// 	if (hasDiagnosticRelatedInformationCapability) {
		// 		diagnostic.relatedInformation = [
		// 			{
		// 				location: {
		// 					uri: textDocument.uri,
		// 					range: Object.assign({}, diagnostic.range)
		// 				},
		// 				message: 'Spelling matters'
		// 			},
		// 			{
		// 				location: {
		// 					uri: textDocument.uri,
		// 					range: Object.assign({}, diagnostic.range)
		// 				},
		// 				message: 'Particularly for names'
		// 			}
		// 		];
		// 	}
		// 	diagnostics.push(diagnostic);
		// }

	}

	visitProgram(ctx: ProgramContext) {
		return null;
	}

	protected defaultResult(): null {
		return null;
	}
}